package com.woniuxy.cloud.ticket52.movieassembly.apiimpl;


import com.woniuxy.cloud.ticket52.CommentAPI;
import com.woniuxy.cloud.ticket52.common.result.Result;
import com.woniuxy.cloud.ticket52.form.CommentAddForm;
import com.woniuxy.cloud.ticket52.movieassembly.model.Comment;
import com.woniuxy.cloud.ticket52.movieassembly.service.ICommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 电影评论 前端控制器
 * </p>
 *
 * @author rc
 * @since 2021-05-06
 */
@RestController
@Slf4j
public class CommentController implements CommentAPI {

    @Autowired
    private ICommentService icommentService;

    @Override
    public Result addcomment(CommentAddForm form) {
        log.info("添加评论{}",form);
        Comment comment = new Comment();
        BeanUtils.copyProperties(form, comment);
        icommentService.save(comment);
        return Result.success();
    }

    @Override
    public Result getcomment(int movie_id) {
        log.info("获取电影{}评论",movie_id);
        Comment byMid = icommentService.findByMid(movie_id);
        return Result.success(byMid);
    }
}

